package com.fnst.caesar.util;

import java.io.*;

import javax.servlet.http.*;

import org.apache.ibatis.io.*;
import org.apache.ibatis.session.*;

public class SqlFactoryUtil
{
	public static SqlSessionFactory getSqlSessionFactory(HttpServletRequest request) throws IOException
	{
		SqlSessionFactory ssf = (SqlSessionFactory)request.getSession(true).getAttribute("SqlSessionFactory");
		if(ssf == null)
		{
			String config = "com/fnst/caesar/MyBatisConfig.xml";
			Reader reader = Resources.getResourceAsReader(config);
			SqlSessionFactoryBuilder ssfb = new SqlSessionFactoryBuilder();
			ssf = ssfb.build(reader);
			request.getSession(true).setAttribute("SqlSessionFactory", ssf);
		}
		return ssf;
	}
}
